<?php

namespace Tests\SJSJ;

use Fize\Database\Db;
use PHPUnit\Framework\TestCase;

class TestFrankOtherAgency extends TestCase
{

    protected function setUp(): void
    {
        $config = [
            'host'     => '586b062079552.bj.cdb.myqcloud.com',
            'port'     => 17149,
            'user'     => 'liujianzhong',
            'password' => 'ljz@#123',
            'dbname'   => 'yhqhcms_db'
        ];
        new Db('mysql', $config, 'pdo');
    }

    public function testFixData()
    {
        $rows = Db::table('frank_other_agency')->select();
        foreach ($rows as $row) {
            $json_data = json_decode($row['data'], true);
            if (isset($json_data['userId']) && $row['trackUserId'] == 0) {
                $data = [
                    'trackUserId' => $json_data['userId']
                ];
                Db::table('frank_other_agency')->where("`id` = ?", [$row['id']])->update($data);
                print_r("{$row['id']} 处理完成！");
            } else {
                print_r("{$row['id']} 不含userId字段，无需处理！");
            }
        }
        print_r("处理完成！");
        self::assertIsArray($rows);
    }

    public function testStrMapping()
    {
        $result = null;
        $def_results = [
            '1' => ['1' => '已跟进'],
            '2' => ['1 => 转移方已同意', '6' => '转移方已拒绝'],
            '3' => ['1 => 接收方已同意', '6' => '接收方已拒绝']
        ];
        $agency = [
            'type' => 1,
        ];
        $status = 1;
        if (is_null($result)) {
            $result = $def_results[(string)$agency['type']][(string)$status];
        }
        var_dump($result);
        self::assertEquals('已跟进', $result);
    }
}
